package jp.co.systemi.asp.workflow;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import org.apache.wicket.RequestCycle;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class ErrorPage extends Super {
    static Logger syslog = Logger.getLogger(ErrorPage.class.getName());

    public ErrorPage(RuntimeException e){
        RequestCycle cycle = getRequestCycle();
        HttpServletRequest request =
            ((ServletWebRequest) cycle.getRequest()).getHttpServletRequest();
        String ipAddress = request.getRemoteAddr();

        StringBuffer errmsg = new StringBuffer();
        errmsg.append("CLIENT_IP:").append(ipAddress);
        UserService userService = UserServiceFactory
            .getUserService();

        com.google.appengine.api.users.User usr = userService
                .getCurrentUser();
        if (usr != null) {
            errmsg.append(",USER_ID:" + usr.getEmail());
        }
        WorkflowSession session = (WorkflowSession)getSession();
        session.logout();
        syslog.fine(errmsg.toString());
    }
}
